<?php

namespace App\Traits;

trait RetrunService
{
    //成功返回

    public static function success($data = [], $code = 200,$msg='')
    {
        return response()->json([
            'status'  => true,
            'code'    => $code,
            'message' => $msg??config('errorcode.code')[(int) $code],
            'data'    => $data,
        ]);
    }

    //失败返回
    public static function fail($message = '', $code=500)
    {

        if($message == '')$message = config('errorcode.code')[(int) $code];

        return response()->json([
            'status'  => false,
            'code'    => $code,
            'message' => $message,
        ]);

    }
}
